﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DLV.Data.Entities;
using DLV.Utilities;
namespace DLV.BackEnd.Pages
{
    public partial class ListTours : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                LoadMenu_Doc();
                List<TourInfo> list = new TourController().ListTour();
                DataTable tb = CBO.ConvertToDataTable(list, typeof(TourInfo));
                GvPhanTrang(tb, ref GridView1, 20, 0);
            }
        }
        private DataTable LoadContinent()
        {
            var ds = new DataSet();
            ds.ReadXml(MapPath("~/xml/Continent.xml"));
            DataTable dv = ds.Tables["Continent"];
            return dv;
        }
        private void LoadMenu_Doc()
        {

            DataTable tb = LoadContinent(), tb2;
            String Ma = "", Ten = "", str = " <div id='cssmenu'><ul> ";
            for (int i = 0; i < tb.Rows.Count; i++)//cấp 1
            {
                Ma = tb.Rows[i]["ID"].ToString();
                Ten = tb.Rows[i]["Name"].ToString();
                List<NationalInfo> list = new NationalController().ListNationalByContinent(Convert.ToInt32(tb.Rows[i]["ID"].ToString()));
                tb2 = CBO.ConvertToDataTable(list, typeof(NationalInfo));
                String StrClass = "";
                if (tb2.Rows.Count > 0) StrClass = "class='has-sub'";

                else
                {
                    StrClass = "class='last'";

                }
                if (tb2.Rows.Count == 0)
                {
                    str += String.Format("<li " + StrClass + "><a href='ListTours.aspx?l=qg&&id={0}'><span>{1}</span></a> </li>", "none", Ma, Ten);
                }
                else
                {
                    str += String.Format("<li " + StrClass + "><a href='#'><span>{0}</span></a>", Ten);
                    str += "  <ul> ";
                    for (int j = 0; j < tb2.Rows.Count; j++)
                    {
                        str += String.Format("<li class='last'>" +
                                             "<a href='ListTours.aspx?l=qg&&id={0}'> " +
                                             "<span class='span_mnu'><img class='img_QuocGia' src='../{1}' />" +

                                                  "  </span><span class='span_mnu name_QuocGia'>{2}</span>" +
                                             " </a></li>", tb2.Rows[j]["NationalId"], tb2.Rows[j]["NationalImg"], tb2.Rows[j]["NationalName"]);
                    }
                    str += "</ul></li>";
                }
            }
            str += "</ul></div>";
            lbMenuD.Text = str;
        }
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            DataTable tb = null;
            try
            {
                String Loai = Request.QueryString["l"].ToString();

                if (Loai == "qg")
                {
                    //tb = TinTuc.LayDSTinMoi();
                }

            }
            catch (Exception)
            {
                List<TourInfo> list = new TourController().ListTour();
              tb = CBO.ConvertToDataTable(list, typeof(TourInfo));
            }
            GvPhanTrang(tb, ref GridView1, 20, e.NewPageIndex);
        }
        public Boolean GvPhanTrang(DataTable tb, ref GridView gv, int SoTrang, int TrangHienTai)
        {
            try
            {

                gv.DataSource = tb;
                gv.AllowPaging = true;
                gv.PageIndex = TrangHienTai;
                gv.PageSize = SoTrang;
                gv.DataBind();
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}